package particlesystem.graphics {
	import flash.display.BitmapData;

	/**
	 * @author robertthurston
	 */
	public class BitmapAnimation {

		private var totalFrames : int;
		private var currentFrame : int;
		private var animation : Array;

		public function BitmapAnimation(animation : Array, randomStartFrame : Boolean = false) {
			this.animation = animation;
			
			totalFrames = animation.length;
			currentFrame = (randomStartFrame) ? Math.floor(Math.random() * totalFrames) + 1 : 1;
		}

		public function getNextFrame() : BitmapData {
			var bitmapData : BitmapData = animation[currentFrame - 1];
			
			currentFrame++;
			
			//currentFrame = ++currentFrame%totalFrames;

			if(currentFrame > totalFrames) {
				currentFrame = 1;
			}
			
			return bitmapData;
		}
	}
}
